package com.open.exam.mapper;

import com.open.exam.databasemodel.ExamComputer;
import com.open.exam.dto.ExamComputerInfoModel;
import com.open.exam.sqlprovider.ExamComputerProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author naicha
 * Created on 2017/11/17.
 */
@Mapper
public interface ExamComputerMapper {

    @Select("SELECT * FROM ExamComputer WHERE ExamRoomID = #{examRoomID} AND SeatNo = #{seatNo} LIMIT 1")
    ExamComputer getExamComputerBySomeWhere(@Param(value = "examRoomID") String examRoomID, @Param(value = "seatNo") Integer seatNo);

    @Select("SELECT * FROM ExamComputer WHERE ExamRoomID = #{examRoomID} ")
    List<ExamComputer> getAllComputer(@Param(value = "examRoomID") String examRoomID);

    @SelectProvider(type = ExamComputerProvider.class,method = "getAllExamComputer")
    List<ExamComputerInfoModel> getAllExamComputer(@Param(value = "appID") String appID, @Param(value = "examSiteID") String examSiteID, @Param(value = "planId") String planId);

    @SelectProvider(type = ExamComputerProvider.class,method = "findExamComputerBySomeWhere")
    List<ExamComputer> findExamComputerBySomeWhere(@Param(value = "examRoomID") String examRoomID, @Param(value = "seatNo") Integer seatNo, @Param(value = "computerIP") String computerIP);

    @Insert("INSERT INTO ExamComputer (ExamRoomID,ComputerIP,SeatNo,UpdateTime,IPRuleType) VALUES(#{examRoomID},#{computerIP},#{seatNo},NOW(),#{iPRuleType})")
    Integer insertExamComputer(ExamComputer examComputer);

    @Update("UPDATE ExamComputer SET ComputerIP = #{computerIP},SeatNo = #{seatNo} WHERE ExamComputerID = #{examComputerID}")
    Integer updataExamComputer(ExamComputer computer);

    @DeleteProvider(type = ExamComputerProvider.class,method = "deleteExamComputerByIds")
    Integer deleteExamComputerByIds(@Param(value = "ids") List<Integer> ids);

    @Select("SELECT * FROM ExamComputer WHERE ComputerIP = #{computerIP} LIMIT 1")
    ExamComputer findExamComputerByIp(@Param("computerIP") String computerIP);
}
